<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        .box {
            width: 200px;
            height: 200px;
            background-color: #6ff;
            margin: 50px;
            overflow: hidden;
        }

        .sub {
            width: 100px;
            height: 100px;
            background-color: pink;
            margin: 50px;

        }
    </style>
</head>

<body>
    <div class="box">
        <div class="sub"></div>
    </div>
</body>
<script>
    // onmouseover onmouseout的问题: (老版本)
    // 给父元素绑定事件onmouseover onmouseout ,滑过子元素时也会触发 (原因:事件冒泡) -> 但是如果不想让子元素触发父元素onmouseover onmouseout 如何解决?

    // 解决方法: 用onmouseenter onmouseleave (新版本) 替换 onmouseover onmouseout

    var box = document.getElementsByClassName("box")[0];

    // box.onmouseover = function () {
    //     console.log("鼠标移入");
    // }

    // box.onmouseout = function () {
    //     console.log("鼠标移出");
    // }

    box.onmouseenter = function () {
        console.log("鼠标移入");
    }

    box.onmouseleave = function () {
        console.log("鼠标移出");
    }







</script>

</html>